package com.buobao.i18n;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.util.Properties;

/**
 * 反射的具体使用示例
 * 这个示例表明具体类实现和调用是不需要修改的，只需要修改配置文件就可以调用到不同类的方法
 */
public class Application {
    public static void main(String[] args) {
        say();
    }

    public static void say() {
        Properties properties = new Properties();
        String path = Application.class.getResource("./config.properties").getPath();
        try {
            path = URLDecoder.decode(path,"UTF-8");
            properties.load(new FileInputStream(path));
            String language = properties.getProperty("language");
            I18N i18N = (I18N) Class.forName(language).getConstructor().newInstance();
            System.out.println(i18N.say());
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}
